![]() |
Kinetis SDK API Reference Manual
1.0.0-beta
Freescale Semiconductor, Inc.
|
The section describes the programming interface of the SPI HAL driver. More...
Data Structures | |
| struct | spi_config_t |
| SPI hardware configuration settings. More... | |
Configuration | |
| void | spi_hal_init (uint32_t instance, const spi_config_t *config) |
| Configures the SPI peripheral. | |
| void | spi_hal_reset (uint32_t instance) |
| Restores the SPI to reset the configuration. | |
| static void | spi_hal_enable (uint32_t instance) |
| Enables the SPI peripheral. | |
| static void | spi_hal_disable (uint32_t instance) |
| Disables the SPI peripheral. | |
| void | spi_hal_set_baud (uint32_t instance, uint32_t kbitsPerSec) |
| Sets the SPI baud rate in kilobits per second. | |
| static void | spi_hal_set_baud_divisors (uint32_t instance, uint32_t prescaleDivisor, uint32_t rateDivisor) |
| Configures the baud rate divisors manually. | |
| static void | spi_hal_set_master_slave (uint32_t instance, spi_master_slave_mode_t mode) |
| Configures the SPI for master or slave. | |
| void | spi_hal_set_slave_select_output_mode (uint32_t instance, spi_ss_output_mode_t mode) |
| Sets how the slave select output operates. | |
| void | spi_hal_set_data_format (uint32_t instance, spi_clock_polarity_t polarity, spi_clock_phase_t phase, spi_shift_direction_t direction) |
| Sets the polarity, phase, and shift direction. | |
| void | spi_hal_set_pin_mode (uint32_t instance, spi_pin_mode_t mode) |
| Sets the SPI pin mode. | |
DMA | |
| void | spi_hal_configure_dma (uint32_t instance, bool enableTransmit, bool enableReceive) |
| Configures the transmit and receive DMA requests. | |
Low power | |
| static void | spi_hal_configure_stop_in_wait_mode (uint32_t instance, bool enable) |
| Enables or disables the SPI clock to stop when the CPU enters wait mode. | |
Interrupts | |
| static void | spi_hal_enable_receive_and_fault_interrupt (uint32_t instance) |
| Enables the receive buffer full and mode fault interrupt. | |
| static void | spi_hal_disable_receive_and_fault_interrupt (uint32_t instance) |
| Disables the receive buffer full and mode fault interrupt. | |
| static void | spi_hal_enable_transmit_interrupt (uint32_t instance) |
| Enables the transmit buffer empty interrupt. | |
| static void | spi_hal_disable_transmit_interrupt (uint32_t instance) |
| Disables the transmit buffer empty interrupt. | |
| static void | spi_hal_enable_match_interrupt (uint32_t instance) |
| Enables the match interrupt. | |
| static void | spi_hal_disable_match_interrupt (uint32_t instance) |
| Disables the match interrupt. | |
Status | |
| static bool | spi_hal_is_read_buffer_full (uint32_t instance) |
| Checks whether the read buffer is full. More... | |
| static bool | spi_hal_is_transmit_buffer_empty (uint32_t instance) |
| Checks whether the transmit buffer is empty. More... | |
| static bool | spi_hal_is_mode_fault (uint32_t instance) |
| Checks whether a mode fault occurred. | |
| void | spi_hal_clear_mode_fault (uint32_t instance) |
| Clears the mode fault flag. | |
| static bool | spi_hal_is_match (uint32_t instance) |
| Checks whether the data received matches the previously-set match value. | |
| void | spi_hal_clear_match (uint32_t instance) |
| Clears the match flag. | |
Data transfer | |
| static uint8_t | spi_hal_read_data (uint32_t instance) |
| Reads a byte from the data buffer. | |
| static void | spi_hal_write_data (uint32_t instance, uint8_t data) |
| Writes a byte into the data buffer. | |
Match byte | |
| static void | spi_hal_set_match_value (uint32_t instance, uint8_t matchByte) |
| Sets the value which triggers the match interrupt. | |
| struct spi_config_t |
Use an instance of this structure with spi_hal_init(). This allows you to configure the
most common settings of the SPI peripheral with a single function call.
The kbitsPerSec member is handled separately. If this value is set to 0, then the baud is
not set by spi_hal_init(), and must be set with a separate call to either the spi_hal_set_baud()
or the spi_hal_set_baud_divisors(). This can be useful if you know the divisors in advance and
don't want to spend the time to compute them for the provided rate in kilobits/sec.
Data Fields | |
| bool | isEnabled |
| Set to true to enable the SPI peripheral. More... | |
| uint32_t | kbitsPerSec |
| Baud rate in kilobits per second. More... | |
| spi_master_slave_mode_t | masterOrSlave |
| Whether to put the peripheral in master or slave mode. More... | |
| spi_clock_polarity_t | polarity |
| Clock polarity setting. More... | |
| spi_clock_phase_t | phase |
| Clock phase setting. More... | |
| spi_shift_direction_t | shiftDirection |
| Direction in which data is shifted out. More... | |
| spi_ss_output_mode_t | ssOutputMode |
| Output mode for the slave select signal. More... | |
| spi_pin_mode_t | pinMode |
| Pin mode with bidirectional option. More... | |
| bool | enableReceiveAndFaultInterrupt |
| Enable for the receive and fault interrupt. More... | |
| bool | enableTransmitInterrupt |
| Enable for the transmit interrupt. More... | |
| bool | enableMatchInterrupt |
| Enable for the match interrupt. More... | |
| bool spi_config_t::isEnabled |
| uint32_t spi_config_t::kbitsPerSec |
| spi_master_slave_mode_t spi_config_t::masterOrSlave |
| spi_clock_polarity_t spi_config_t::polarity |
| spi_clock_phase_t spi_config_t::phase |
| spi_shift_direction_t spi_config_t::shiftDirection |
| spi_ss_output_mode_t spi_config_t::ssOutputMode |
| spi_pin_mode_t spi_config_t::pinMode |
| bool spi_config_t::enableReceiveAndFaultInterrupt |
| bool spi_config_t::enableTransmitInterrupt |
| bool spi_config_t::enableMatchInterrupt |
| enum spi_status_t |
| enum spi_clock_polarity_t |
| enum spi_clock_phase_t |
| enum spi_ss_output_mode_t |
| enum spi_pin_mode_t |
|
inlinestatic |
The read buffer full flag is only cleared by reading it when it is set, then reading the data register by calling the spi_hal_read_data(). This example code demonstrates how to check the flag, read data, and clear the flag.
|
inlinestatic |
To clear the transmit buffer empty flag, you must first read the flag when it is set. Then write a new data value into the transmit buffer with a call to the spi_hal_write_data(). The example code shows how to do this.